package io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ReadStringDemo {
    public static void main(String[] args) throws IOException {
        File file = new File("test.txt");
        FileInputStream fis = new FileInputStream(file);
        byte[] data = new byte[(int)file.length()];
        fis.read(data);//将文件中的数据一次性读入到字节数组中
        String str = new String(data, StandardCharsets.UTF_8);//将字节数组转换为字符串
        System.out.println(str);
        fis.close();

        ;

    }
}
